from numbers import triangonal, pentagonal, hexagonal

t = triangonal()
p = pentagonal()
h = hexagonal()

nextP = p.next()
nextH = h.next()

while True:
    nextT = t.next()
    while nextT > nextP: nextP = p.next()
    while nextT > nextH: nextH = h.next()
    if nextT == nextP and nextT == nextH:
        print nextT